// pages/user/accounputForward/accounputForward.js
var app = getApp();
var WxParse = require('../../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataInfo: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getRule();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getIdentityInfo();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  // 提现
  withdrawal() {
    var that = this;
    var is_have_bank = that.data.dataInfo.is_have_bank;
    if (is_have_bank){
      wx.navigateTo({
        url: '../putForwardPrice/putForwardPrice'
      })
    }else{
      wx.showModal({
        content: '请先绑定银行卡',
        showCancel: false,
        success(res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '../addeditAccount/addeditAccount?type=2',
            })
          }
        }
      })
    }
    
  },

  // 获取用户身份信息
  getIdentityInfo() {
    var that = this;
    var user_id = wx.getStorageSync('user_id');
    app.ajax({
      url: 'User/Channel/getUserIdentityInfo',
      data: {
        user_id: user_id
      },
      success: function (res) {
        if (res.data.code == 1000) {
          that.getInfo(res.data.data.identity);
        }
      }
    })
  },
  // 获取个人信息
  getInfo(identity) {
    var that = this;
    var user_id = wx.getStorageSync('user_id');
    var _url = '';
    if (identity == 2) { // 渠道商
      _url = 'User/Channel/getChannelInfo';
    } else if (identity == 3) { // 推广商
      _url = 'User/Channel/getPromotersInfo';
    }
    app.ajax({
      url: _url,
      data: {
        user_id: user_id
      },
      success: function (res) {
        if (res.data.code == 1000) {
          that.setData({
            dataInfo: res.data.data
          })
        }
      }
    })
  },

  // 提现记录
  presentRecord(){
    var that = this;
    wx.navigateTo({
      url: '../presentRecord/presentRecord',
    })
  },
  
  // 提现账户设置
  presentAccount(){
    var that = this;
    wx.navigateTo({
      url: '../presentAccount/presentAccount',
    })
  },
  
  // 获取提现说明
  getRule() {
    var that = this;
    app.ajax({
      url: 'Common/Article/getArticle',
      data: {
        cate_sn: 'AVwsyFwB'
      },
      success: function (res) {
        if (res.data.code == 1000) {
          var article = res.data.data[0].content;
          WxParse.wxParse('article', 'html', article, that, 5);
        }
      }
    })
  },
})